import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";

export const useUserStore = defineStore({
  id: "admin-user",
  state: (): UserState => ({
    id: "",
    token: "",
    isSuper: 0
  }),
  getters: {},
  actions: {
    setToken(token: string) {
      this.token = token;
    },
    setIsSuper(isSuper: number) {
      this.isSuper = isSuper;
    },
    setUserId(id: string) {
      this.id = id;
    },
    resetUser() {
      this.id = "";
      this.token = "";
      this.isSuper = 0;
    },
    printState() {
      console.log("当前用户状态:", {
        token: this.token,
        isSuper: this.isSuper,
        id: this.id
      });
    }
  },
  persist: piniaPersistConfig("admin-user")
});
